import http from '../../util/request.js';
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    itemData: {
      type: Object,
      value: {}
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    receiveImg: '/weidun_card/images/receive.png',
    receiveHoverImg: '/weidun_card/images/receive_hover.png',
    praiseImg: '/weidun_card/images/like.png',
    praiseHoverImg: '/weidun_card/images/like_hover.png',
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleTap() {
      console.log('tap')
    },
    receive: function (e) {
      var that = this;
      var id = e.currentTarget.id;
      var item = that.data.itemData;
      if (item.haveReceive == 1) {
        wx.showToast({
          title: '您已经收藏了',
          icon: 'none'
        });
        return;
      }
      http.get('tips', {
        act: 'receive',
        id: id
      }).then(function (res) {
        wx.showToast({
          title: '收藏成功',
        });
        
        item.haveReceive = 1;
        that.setData({
          itemData: item
        });
      });
    },
    like: function (e) {
      var that = this;
      var id = e.currentTarget.id;
      var item = that.data.itemData;
      if (item.havePraise == 1) {
        wx.showToast({
          title: '您已经点赞了',
          icon: 'none'
        });
        return;
      }
      http.get('tips', {
        act: 'like',
        id: id
      }).then(function (res) {
        wx.showToast({
          title: '点赞成功',
        });
        item.havePraise = 1;
        that.setData({
          itemData: item
        });
      });
    }
  }
})
